'''
Created on 29/09/2011

@author: Ike-kun <ragnell22@gmail.com>
'''

from Logger import Logger
import random

class RandomGenerator(object):
    def __init__(self,logsGenerated):
        self.log = Logger()
        if(self.log.getTarget() == 'xml'):
            if(logsGenerated > 500):
                logsGenerated = 500
        percent = 0.03
        print "Creating Logs"
        for i in range(logsGenerated):
            self.clearNDC()
            self.logInfo("iteration number: "+str(i))
            success = random.randrange(0,100)
            if(success < 30):
                self.logDebug("debug in iteration: "+str(i))
            if(success < 15):
                self.setNDC("warning territory")
                self.logWarn("warning in iteration: "+str(i))
            if(success < 7):
                self.setNDC("error territory")
                self.logError("error in iteration: "+str(i))
            if(success < 1):
                self.setNDC("fatal territory")
                self.logFatal("fatal in iteration: "+str(i))
            if(int(logsGenerated * percent) == i):
                print str(int(percent * 100)) + "% completed"
                percent = percent + 0.03
        self.log.closeAppendFile()

    def logInfo(self,msg):
        self.log.info(msg)

    def logWarn(self,msg):
        self.log.warn(msg)

    def logError(self,msg):
        self.log.error(msg)

    def logFatal(self,msg):
        self.log.fatal(msg)
        
    def logDebug(self,msg):
        self.log.debug(msg)

    def setNDC(self,msg):
        self.log.pushNDC(msg)

    def clearNDC(self):
        self.log.clearNDC()
        
if __name__ == "__main__":
    RandomGenerator(30000)
    print "Logs has been created!!"
